package com.dog.basics.admin.controller.mtkj;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.UserAddrFromDto;
import com.dog.basics.bean.vo.admin.mtkj.UserAddrFromVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtUserAddrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * <p>
 * 用户配送地址 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@Api(value = "用户地址管理模块", tags = "用户地址管理模块")
@RestController
@RequestMapping("/admin/useraddr")
@AllArgsConstructor
public class MtUserAddrController {

    private final IMtUserAddrService userAddrService;

    /**
     * 查询用户地址
     * @param: page
     * @param: fromDto
     * @returns
     * @author hangdy
     * @date: 2020/11/14 12:50
     */
    @ApiOperation(value = "用户配送地址列表", notes = "admin:useraddr:findUserAddr")
    @GetMapping("/findUserAddr")
    @PreAuthorize("@pms.hasPermission('admin:useraddr:findUserAddr')")
    public R<IPage<UserAddrFromVo>> findUserAddrs(PageParam page , UserAddrFromDto fromDto){
        return R.ok(userAddrService.findUserAddr(page,fromDto));
    }



    /**
     * 删除用户地址
     * @param id
     * @return
     * @author hangdy
     */
    @SysLog("删除用户配送地址")
    @ApiOperation(value = "删除用户配送地址", notes = "pc:useraddr:deleteUserAddr")
    @ApiImplicitParam(value = "用户配送地址Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/deleteUserAddr/{id}")
    @PreAuthorize("@pms.hasPermission('pc:useraddr:deleteUserAddr')")
    public R<Boolean> delete(@Valid @PathVariable("id") Long id) {
        return R.ok(userAddrService.adminDeleteUserAddr(id));
    }
}
